package com.sky.controller.admin;

import com.sky.constant.JwtClaimsConstant;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.dto.PasswordEditDTO;
import com.sky.entity.Employee;
import com.sky.mapper.EmployeeMapper;
import com.sky.properties.JwtProperties;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.EmployeeService;
import com.sky.utils.JwtUtil;
import com.sky.vo.EmployeeLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author：XueShiHao
 * @Date：2025/6/3 星期二 10:49:48
 * @Email:747278007@qq.com
 * @Description:
 **/
@Slf4j
@RestController
@RequestMapping("/admin/employee")
@Api("员工相关的接口")
public class EmployeeController {
  @Autowired
    private EmployeeService employeeService;
  @Autowired
  private JwtProperties jwtProperties;
    @ApiOperation("员工登录")
    @PostMapping("/login")
    public Result login(@RequestBody EmployeeLoginDTO employeeLoginDTO){
     Employee employee= employeeService.login(employeeLoginDTO);
        //登录成功之后生成Token
        Map<String,Object> claims=new HashMap<>();
        claims.put(JwtClaimsConstant.EMP_ID,employee.getId());
        String token= JwtUtil.createJWT(jwtProperties.getAdminSecretKey(),
                jwtProperties.getAdminTtl(),
                claims);
        //以vo格式将数据封装传回给前端
        EmployeeLoginVO employeeLoginVO=EmployeeLoginVO.builder()
                .id(employee.getId())
                .userName(employee.getUsername())
                .name(employee.getName())
                .token(token)
                .build();
        //登录成功之后生成Token
        return Result.success(employeeLoginVO);
    }
    @ApiOperation("员工信息的分页")
    @GetMapping("/page")
public Result<PageResult>  page(EmployeePageQueryDTO employeePageQueryDTO){
        log.info("员工分页查询。参数为：{}",employeePageQueryDTO);
        PageResult pageResult=employeeService.pageQuery(employeePageQueryDTO);
        return Result.success(pageResult);

    }
    @ApiOperation("根据id查询员工")
    @GetMapping("/{id}")
    public Result<Employee> gg(@PathVariable Long id){
        log.info("所查询的员工的id为：{}",id);
        Employee employee=employeeService.getById(id);
        return Result.success(employee);
    }
    @ApiOperation("新增员工")
    @PostMapping
    public Result insert(@RequestBody EmployeeDTO employeeDTO){
        employeeService.save(employeeDTO);
        log.info("员工增加成功");
        return Result.success();
    }
    @ApiOperation("启动禁用员工状态")
    @PostMapping("/status/{status}")
    public Result startOrStop(@PathVariable Integer status,Long id){
        employeeService.startOrStop(status,id);
        log.info("启用禁用的员工的账户:{},{}",status,id);
        return Result.success();
    }
    @ApiOperation("修改密码")
    @PutMapping("/editPassword")
    public Result editPassword(@RequestBody PasswordEditDTO passwordEditDTO){

        return null;
    }
    /**









   @ApiOperation("根据id查询员工")
    @GetMapping("/{id}")

    @ApiOperation("编辑员工信息")
    @PutMapping
    @ApiOperation("员工退出功能")
    @PostMapping("/logout")
    */
}
